public class Test1 {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0, right = 0;
        int sum = 0, minLength = nums.length + 1;
        while(right < nums.length){
            sum += nums[right];
            while(sum >= target){
                minLength = Math.min(minLength,right - left  + 1);
                sum -= nums[left];
                left++;
            }
            right++;
        }
        return minLength == nums.length + 1?0:minLength;
    }
}
